package pers.cz.json;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import springfox.documentation.spring.web.json.Json;

import java.util.Iterator;

/**
 * @program: PostGirl-panent
 * @description: test
 * @author: Cheng Zhi
 * @create: 2021-03-16 21:05
 **/
public class Test {

    public static void main(String[] args) {

        // System.out.println(test1());
        test3();
    }

    public static String test1() {
        String jsonStr = "[\n" +
                "  {\n" +
                "    \"acct_id\": 31070038925,\n" +
                "    \"asset_id\": 200049395392099,\n" +
                "    \"pocket_item\": 5960002,\n" +
                "    \"pocket_name\": \"新入网充值送赠费\",\n" +
                "    \"amount\": 0,\n" +
                "    \"unpay_fee\": 0,\n" +
                "    \"real_fee\": 0,\n" +
                "    \"sts\": 0,\n" +
                "    \"billing_type\": 1,\n" +
                "    \"valid_date\": \"2019-04-01 00:00:00\",\n" +
                "    \"expire_date\": \"2019-04-30 00:00:00\",\n" +
                "    \"resource_id\": 0,\n" +
                "    \"is_common_pocket\": 0,\n" +
                "    \"is_reward\": 1,\n" +
                "    \"freeze_value\": 0,\n" +
                "    \"freeze_time\": 20190430,\n" +
                "    \"measure_id\": 10403,\n" +
                "    \"deduct_amount\": 0,\n" +
                "    \"allow_adjust\": 1,\n" +
                "    \"allow_refund\": 1,\n" +
                "    \"priority\": 9800,\n" +
                "    \"itemType\": \"3\"\n" +
                "  }\n" +
                "]";

        //JSONObject jsonObject = (JSONObject) JSONObject.parse(jsonStr);
        String aaa = jsonStr;
        //JSONArray jsonArray = JSONArray.parseArray(jsonStr);
        JSONArray jsonArray = JSONArray.parseArray(aaa);
        JSONObject jsonSave = (JSONObject) jsonArray.get(0);
//        /jsonSave.put("amout",100);
        return jsonSave.toString();
    }

    public void test2() {
        String jsonStr = "{\"doQuerySuccess\":1,\"saveFundQryOut\":{\"acctId\":31070038925,\"userId\":40200075634383,\"phoneId\":\"18800270336\",\"acctName\":\"割接\",\"disAcctName\":\"割*\",\"hisUnPayFee\":0,\"hisUnPayFeeDouble\":0.0,\"realFee\":3900,\"realFeeDouble\":39.0,\"osStatusName\":\"正常使用,未停机\",\"osStatus\":0,\"acctFee\":0,\"pocketFee\":42999,\"pocketFeeDouble\":429.99,\"rowIndex\":0,\"saveFee\":0,\"saveFeeDouble\":0.0,\"lastFee\":0,\"accCode\":0,\"assetItemId\":0,\"payMethod\":0,\"busiCode\":0,\"isSelfPhone\":0,\"payType\":0,\"isGolbeTrip\":false,\"operId\":0,\"balanceAmt\":0,\"bankCode\":0,\"main_soNbr\":0,\"bindTime\":0,\"discount\":false,\"selfDefine\":false,\"returnBili\":0,\"userExpireDate\":\"2099-12-31 23:59:59\",\"acctType\":0,\"custId\":21010065637513,\"realNameSts\":2,\"brandId\":7,\"signCreditControl\":0,\"deductFee\":0,\"deductFeeDouble\":0.0,\"usableFee\":39099,\"usableFeeDouble\":390.99,\"isOutTrip\":false,\"isOrgTrip\":false,\"isABMOk\":true,\"isAPSOk\":true,\"isPreFeeAllow\":false,\"taxType\":\"0\"},\"success\":true}";
        JSONObject jsonObject = (JSONObject) JSONObject.parse(jsonStr);
        JSONObject jsonSave = (JSONObject) jsonObject.get("saveFundQryOut");
        jsonSave.put("realFee",0);
        jsonSave.put("realFeeDouble",0);
        jsonSave.put("pocketFee",3000);
        jsonSave.put("usableFee",3000);
        jsonSave.put("usableFeeDouble",30);
        jsonSave.remove("acctName");
        jsonSave.remove("disAcctName");

        System.out.println(jsonSave.toString());
    }

    public static void test3() {

        String jsonStr = "{\"doQuerySuccess\":1,\"saveFundQryOut\":{\"acctId\":31070038925,\"userId\":40200075634383,\"phoneId\":\"18800270336\",\"acctName\":\"割接\",\"disAcctName\":\"割*\",\"hisUnPayFee\":0,\"hisUnPayFeeDouble\":0.0,\"realFee\":3900,\"realFeeDouble\":39.0,\"osStatusName\":\"正常使用,未停机\",\"osStatus\":0,\"acctFee\":0,\"pocketFee\":63999,\"pocketFeeDouble\":639.99,\"rowIndex\":0,\"saveFee\":0,\"saveFeeDouble\":0.0,\"lastFee\":0,\"accCode\":0,\"assetItemId\":0,\"payMethod\":0,\"busiCode\":0,\"isSelfPhone\":0,\"payType\":0,\"isGolbeTrip\":false,\"operId\":0,\"balanceAmt\":0,\"bankCode\":0,\"main_soNbr\":0,\"bindTime\":0,\"discount\":false,\"selfDefine\":false,\"returnBili\":0,\"userExpireDate\":\"2099-12-31 23:59:59\",\"acctType\":0,\"custId\":21010065637513,\"realNameSts\":2,\"brandId\":7,\"signCreditControl\":0,\"deductFee\":0,\"deductFeeDouble\":0.0,\"usableFee\":60099,\"usableFeeDouble\":600.99,\"isOutTrip\":false,\"isOrgTrip\":false,\"isABMOk\":true,\"isAPSOk\":true,\"isPreFeeAllow\":true,\"taxType\":\"0\"},\"success\":true}";
        JSONObject jsonObject = (JSONObject) JSONObject.parse(jsonStr, Feature.OrderedField);
        JSONObject jsonSave = (JSONObject) jsonObject.get("saveFundQryOut");
        jsonSave.put("realFee",0);
        jsonSave.put("realFeeDouble",0);
        jsonSave.put("pocketFee",3000);
        jsonSave.put("usableFee",3000);
        jsonSave.put("usableFeeDouble",30);
        jsonSave.put("isPreFeeAllow",false);
        jsonSave.put("pocketFeeDouble",30);
        jsonSave.remove("acctName");
        jsonSave.remove("disAcctName");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(jsonSave);

        System.out.println(jsonArray.toString());
    }
}
